package cn.swpu.service.impl;

import cn.swpu.bose.DaoSupportImpl;

import cn.swpu.domin.Department;
import cn.swpu.service.DepartmentService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by 11616 on 2016/7/18.
 */
@Service
@Transactional
@SuppressWarnings("unchecked")
public class DepartmentServiceImpl extends DaoSupportImpl<Department> implements DepartmentService {
//    @Resource
//    private DepartmentDao departmentDao;

//    @Override
//    public List<Department> findAll() {
//        return departmentDao.findAll();
//    }
//
//    @Override
//    public void save(Department department) {
//        departmentDao.save(department);
//    }
//
//    @Override                                         /******* 删除Dao层
//    public Department findById(Long id) {
//        return departmentDao.findById(id);
//    }
//
//    @Override
//    public void update(Department department) {
//           departmentDao.update(department);
//    }
//





    @Override
    public List<Department> findTopAll() {

        return sessionFactory.getCurrentSession().createQuery("from Department d where d.parent is null").list();
    }

    @Override
    public List<Department> findChildrenAll(Long parentId) {
        return sessionFactory.getCurrentSession().createQuery("from Department d where d.parent.id = ?")
                .setParameter(0,parentId)
                .list();
    }
}
